<!--

    Copyright © 2016-2024 The Thingsboard Authors

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<div class="tb-form-row space-between same-padding tb-flex column" [formGroup]="securityFormGroup">
  <div class="tb-flex row space-between align-center no-gap fill-width">
    <div class="fixed-title-width tb-required">{{ title | translate }}</div>
    <tb-toggle-select formControlName="type" appearance="fill">
      <tb-toggle-option *ngFor="let type of securityTypes" [value]="type">
        {{ SecurityTypeTranslationsMap.get(type) | translate }}
      </tb-toggle-option>
    </tb-toggle-select>
  </div>
  <ng-container [ngSwitch]="securityFormGroup.get('type').value">
    <ng-template [ngSwitchCase]="BrokerSecurityType.BASIC">
      <div class="tb-form-row space-between tb-flex fill-width">
        <div class="fixed-title-width" translate>gateway.username</div>
        <div class="tb-flex no-gap">
          <mat-form-field class="tb-flex no-gap" appearance="outline" subscriptSizing="dynamic">
            <input matInput name="value" formControlName="username" placeholder="{{ 'gateway.set' | translate }}"/>
            <mat-icon matSuffix
                      matTooltipPosition="above"
                      matTooltipClass="tb-error-tooltip"
                      [matTooltip]="('gateway.username-required') | translate"
                      *ngIf="securityFormGroup.get('username').hasError('required')
                                             && securityFormGroup.get('username').touched"
                      class="tb-error">
              warning
            </mat-icon>
          </mat-form-field>
        </div>
      </div>
      <div class="tb-form-row space-between tb-flex fill-width">
        <div class="fixed-title-width" translate>gateway.password</div>
        <div class="tb-flex no-gap">
          <mat-form-field class="tb-flex no-gap" appearance="outline" subscriptSizing="dynamic">
            <input matInput type="password" name="value" formControlName="password" placeholder="{{ 'gateway.set' | translate }}"/>
              <div class="tb-flex no-gap align-center fill-height" matSuffix>
                <tb-toggle-password class="tb-flex align-center fill-height"></tb-toggle-password>
              </div>
          </mat-form-field>
        </div>
      </div>
    </ng-template>
    <ng-template [ngSwitchCase]="BrokerSecurityType.CERTIFICATES">
      <div class="tb-form-hint tb-primary-fill">{{ 'gateway.path-hint' | translate }}</div>
      <div class="tb-form-row space-between tb-flex fill-width">
        <div class="fixed-title-width" translate>gateway.CA-certificate-path</div>
        <div class="tb-flex no-gap">
          <mat-form-field class="tb-flex no-gap" appearance="outline" subscriptSizing="dynamic">
            <input matInput name="value" formControlName="pathToCACert" placeholder="{{ 'gateway.set' | translate }}"/>
          </mat-form-field>
        </div>
      </div>
      <div class="tb-form-row space-between tb-flex fill-width">
        <div class="fixed-title-width" translate>gateway.private-key-path</div>
        <div class="tb-flex no-gap">
          <mat-form-field class="tb-flex no-gap" appearance="outline" subscriptSizing="dynamic">
            <input matInput name="value" formControlName="pathToPrivateKey" placeholder="{{ 'gateway.set' | translate }}"/>
          </mat-form-field>
        </div>
      </div>
      <div class="tb-form-row space-between tb-flex fill-width">
        <div class="fixed-title-width" translate>gateway.client-cert-path</div>
        <div class="tb-flex no-gap">
          <mat-form-field class="tb-flex no-gap" appearance="outline" subscriptSizing="dynamic">
            <input matInput name="value" formControlName="pathToClientCert" placeholder="{{ 'gateway.set' | translate }}"/>
          </mat-form-field>
        </div>
      </div>
      <ng-container *ngIf="extendCertificatesModel">
        <div class="tb-form-row space-between tb-flex fill-width">
          <div class="fixed-title-width" translate>gateway.mode</div>
          <div class="tb-flex no-gap">
            <mat-form-field class="tb-flex no-gap" appearance="outline" subscriptSizing="dynamic">
              <mat-select formControlName="mode">
                <mat-option *ngFor="let type of modeTypes" [value]="type">
                  {{ type }}
                </mat-option>
              </mat-select>
            </mat-form-field>
          </div>
        </div>
        <div class="tb-form-row space-between tb-flex fill-width">
          <div class="fixed-title-width" translate>gateway.username</div>
          <div class="tb-flex no-gap">
            <mat-form-field class="tb-flex no-gap" appearance="outline" subscriptSizing="dynamic">
              <input matInput name="value" formControlName="username" placeholder="{{ 'gateway.set' | translate }}"/>
              <mat-icon matSuffix
                        matTooltipPosition="above"
                        matTooltipClass="tb-error-tooltip"
                        [matTooltip]="('gateway.username-required') | translate"
                        *ngIf="securityFormGroup.get('username').hasError('required')
                                               && securityFormGroup.get('username').touched"
                        class="tb-error">
                warning
              </mat-icon>
            </mat-form-field>
          </div>
        </div>
        <div class="tb-form-row space-between tb-flex fill-width">
          <div class="fixed-title-width" translate>gateway.password</div>
          <div class="tb-flex no-gap">
            <mat-form-field class="tb-flex no-gap" appearance="outline" subscriptSizing="dynamic">
              <input matInput type="password" name="value" formControlName="password" placeholder="{{ 'gateway.set' | translate }}"/>
              <div class="tb-flex no-gap align-center fill-height" matSuffix>
                <tb-toggle-password class="tb-flex align-center fill-height"></tb-toggle-password>
              </div>
            </mat-form-field>
          </div>
        </div>
      </ng-container>
    </ng-template>
  </ng-container>
</div>
